// 这里编写路由权限控制代码
import store from '@/store'
import router from '@/router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
const WHITE_LIST = ['/login', '/404']

router.beforeEach((to, from, next) => {
  // 开启进度条
  NProgress.start()
  if (store.state.user.token) {
    if (to.path === '/login') {
      next('/')
    } else {
      next()
    }
  } else {
    if (WHITE_LIST.includes(to.path)) {
      next()
    } else {
      next('/login')
    }
  }
  // 技术进度条
  NProgress.done()
})
